package xyz.longicorn.driver.controller;

import cn.dev33.satoken.stp.StpUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import xyz.longicorn.driver.dto.ApiResult;
import xyz.longicorn.driver.dto.FileItem;
import xyz.longicorn.driver.dto.FolderDto;
import xyz.longicorn.driver.pojo.FolderInfo;
import xyz.longicorn.driver.pojo.UserInfo;
import xyz.longicorn.driver.service.FolderService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/folder")
@Api("目录操作")
public class FolderController {
    @Resource
    private FolderService folderService;

    @RequestMapping("/list")
    //接口文档的名称
    @ApiOperation(value = "查询目录信息", notes = "查询相应目录下的所有文件(夹)信息", httpMethod = "GET")
    public ApiResult listFolder(@RequestParam(required = false, defaultValue = "/") String folderPath) {
        UserInfo info = StpUtil.getSession().get("user", new UserInfo().setId(0));

        return ApiResult.success(
                folderService.listFolder(StpUtil.getLoginId(0), folderPath)
        );
    }

    // 创建目录
    @PostMapping("/create")
    @ApiOperation(value = "创建目录", notes = "创建目录1")
    public ApiResult create(@RequestBody FolderDto f) {
        String parent = f.getParent(), name = f.getName();
        return ApiResult.success(
                folderService.create(1, parent, name)
        );
    }
}
